import { deleteAction, getAction, postAction, putAction, uploadAction,downloadAction } from '@/api/manage'
import Vue from 'vue'
import { UI_CACHE_DB_DICT_DATA } from '@/store/mutation-types'

//角色管理
const addRole = (params) => postAction('/system/role/add', params)
const editRole = (params) => putAction('/system/role/edit', params)
const checkRoleCode = (params) => getAction('/system/role/checkRoleCode', params)
const queryall = (params) => getAction('/system/role/queryall', params)

//用户管理
const addUser = (params) => postAction('/system/user/add', params)
const editUser = (params) => putAction('/system/user/edit', params)
const queryUserRole = (params) => getAction('/system/user/queryUserRole', params)
const getUserList = (params) => getAction('/system/user/list', params)
const frozenBatch = (params) => putAction('/system/user/frozenBatch', params)
//验证用户是否存在
const checkOnlyUser = (params) => getAction('/system/user/checkOnlyUser', params)
//改变密码
const changePassword = (params) => putAction('/system/user/changePassword', params)

//权限管理
const addPermission = (params) => postAction('/system/permission/add', params)
const editPermission = (params) => putAction('/system/permission/edit', params)
const getPermissionList = (params) => getAction('/system/permission/list', params)
/*update_begin author:wuxianquan date:20190908 for:添加查询一级菜单和子菜单查询api */
const getSystemMenuList = (params) => getAction('/system/permission/getSystemMenuList', params)
const getSystemSubmenu = (params) => getAction('/system/permission/getSystemSubmenu', params)
const getSystemSubmenuBatch = (params) => getAction('/system/permission/getSystemSubmenuBatch', params)

const queryTreeList = (params) => getAction('/system/permission/queryTreeList', params)
const queryTreeListForRole = (params) => getAction('/system/role/queryTreeList', params)
const queryListAsync = (params) => getAction('/system/permission/queryListAsync', params)
const queryRolePermission = (params) => getAction('/system/permission/queryRolePermission', params)
const saveRolePermission = (params) => postAction('/system/permission/saveRolePermission', params)
const queryPermissionsByUser = (params) => getAction('/system/permission/getUserPermissionByToken', params)
const loadAllRoleIds = (params) => getAction('/system/permission/loadAllRoleIds', params)
const getPermissionRuleList = (params) => getAction('/system/permission/getPermRuleListByPermId', params)
const queryPermissionRule = (params) => getAction('/system/permission/queryPermissionRule', params)

//日志管理
//const getLogList = (params)=>getAction("/system/log/list",params);
const deleteLog = (params) => deleteAction('/system/log/delete', params)
const deleteLogList = (params) => deleteAction('/system/log/deleteBatch', params)

//数据字典
const addDict = (params) => postAction('/system/dict/add', params)
const editDict = (params) => putAction('/system/dict/edit', params)
const treeList = (params) => getAction('/system/dict/treeList', params)
const addDictItem = (params) => postAction('/system/dictItem/add', params)
const editDictItem = (params) => putAction('/system/dictItem/edit', params)

//资源管理-货品管理
const addMotorPart = (params) => postAction('/motorfactory/motor-part/add', params)
const editMotorPart = (params) => putAction('/motorfactory/motor-part/update', params)
const getApplicationMotorModelDict = (params) => getAction('/motorfactory/motor-part/getApplicationMotorModelDict', params)
const getPartTypeDict = (params) => getAction('/motorfactory/motor-part/getPartTypeDict', params)
const getMainEngineRelsDict = (params) => getAction('/motorfactory/motor-part/getMainEngineRelsDict', params)
const getRelsByPartId = (params) => getAction('/motorfactory/motor-part/getRelsByPartId', params)
const downloadPartTemplate = () => downloadAction('/motorfactory/motor-part/downloadPartTemplate')

//库存管理-出入库台账信息
const addWarehouseRecord = (params) => postAction('/motorfactory/warehouse-record/add', params)
const editWarehouseRecord = (params) => putAction('/motorfactory/warehouse-record/update', params)
const deleteWarehouseRecord = (params) => deleteAction('/motorfactory/warehouse-record/delete', params)

//供应管理
//主机厂项目
const addMainEngine = (params) => postAction('/motorfactory/main-engine/add', params)
const editMainEngine = (params) => putAction('/motorfactory/main-engine/update', params)
//货品类型
const addPartType = (params) => postAction('/motorfactory/part-type/add', params)
const editPartType = (params) => putAction('/motorfactory/part-type/update', params)
//应用车型
const addApplicationMotorModel = (params) => postAction('/motorfactory/aplication-motor-model/add', params)
const editApplicationMotorModel = (params) => putAction('/motorfactory/aplication-motor-model/update', params)

//文件管理
const uploadFile = (params) => uploadAction(`/file/atta/upload`, params)
const getUploadedPreviewFiles = (params) => getAction('/file/atta/get-uploaded-files', params)

//字典标签专用（通过code获取字典数组）
export const ajaxGetDictItems = (code, params) => getAction(`/system/dict/getDictItems/${code}`, params)

//从缓存中获取字典配置
function getDictItemsFromCache(dictCode) {
  const data = Vue.ls.get(UI_CACHE_DB_DICT_DATA)
  if (data) {
    const dictItems = data[dictCode]
    if (dictItems) {
      return dictItems
    }
  }
}

//上传接口


//获取系统访问量
const getLoginfo = (params) => getAction('/oauth/loginfo', params)
const getVisitInfo = (params) => getAction('/oauth/visitInfo', params)

// 重复校验
const duplicateCheck = (params) => getAction('/system/duplicate/check', params)

export {
  downloadPartTemplate,
  getUploadedPreviewFiles,
  uploadFile,
  addPartType,
  editPartType,
  addApplicationMotorModel,
  editApplicationMotorModel,
  addMainEngine,
  editMainEngine,
  addWarehouseRecord,
  editWarehouseRecord,
  deleteWarehouseRecord,
  getRelsByPartId,
  getApplicationMotorModelDict,
  getPartTypeDict,
  getMainEngineRelsDict,
  addMotorPart,
  editMotorPart,
  addRole,
  editRole,
  checkRoleCode,
  addUser,
  editUser,
  queryUserRole,
  getUserList,
  queryall,
  frozenBatch,
  checkOnlyUser,
  changePassword,
  getPermissionList,
  addPermission,
  editPermission,
  queryTreeList,
  queryListAsync,
  queryRolePermission,
  saveRolePermission,
  queryPermissionsByUser,
  loadAllRoleIds,
  getPermissionRuleList,
  queryPermissionRule,
  deleteLog,
  deleteLogList,
  addDict,
  editDict,
  treeList,
  addDictItem,
  editDictItem,
  getLoginfo,
  getVisitInfo,
  duplicateCheck,
  queryTreeListForRole,
  getSystemMenuList,
  getSystemSubmenu,
  getSystemSubmenuBatch,
  getDictItemsFromCache
}



